//
//  WFThisWeekNewestChannelOnLineViewController.m
//  FAKER
//
//  Created by Jianwei on 15/11/10.
//  Copyright © 2015年 YHLai. All rights reserved.
//

#import "WFThisWeekNewestChannelOnLineViewController.h"
#import "BaseClassTableView.h"
#import "FitHeader.h"
#import "WFNewestChannelTableViewCell.h"
#import "AllHeader.h"
#import "WFSecondChannelListModel.h"
@interface WFThisWeekNewestChannelOnLineViewController ()<UITableViewDataSource, UITableViewDelegate>
@property(nonatomic, strong)BaseClassTableView *backTableView;
@property(nonatomic, strong)NSMutableArray *dataSourceArray;
@end

@implementation WFThisWeekNewestChannelOnLineViewController
- (void)getData
{
    [InternetDataRequest getDataByString:[_model.block_topic objectForKey:@"api_url"] BodyDic:nil WithDataBlock:^(id data) {
        NSArray *array = [[data objectForKey:@"data"] objectForKey:@"list"];
        for (NSDictionary *dic in array) {
            WFSecondChannelListModel *model = [[WFSecondChannelListModel alloc]init];
            [model setValuesForKeysWithDictionary:dic];
            [_dataSourceArray addObject:model];
        }
        [_backTableView reloadData];
    }];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = _model.title;
}
- (void)loadView
{
    [super loadView];
    _dataSourceArray = [NSMutableArray array];
    [self getData];
    _backTableView = [[BaseClassTableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:UITableViewStylePlain];
    _backTableView.delegate = self;
    _backTableView.dataSource = self;
    _backTableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
//    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 70)];
    UIImageView *headerImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 70)];
//    [view addSubview:headerImageView];
    [headerImageView sd_setImageWithURL:[NSURL URLWithString:_model.promotion_img] placeholderImage:[UIImage imageNamed:@"PlaceHolder"]];
    _backTableView.tableHeaderView = headerImageView;
    [self.view addSubview:_backTableView];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"new";
    WFNewestChannelTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[WFNewestChannelTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.selectionStyle = 0;
    cell.newestModel = _dataSourceArray[indexPath.row];
    cell.layer.transform = CATransform3DMakeScale(0.3, 0.3, 0.1);
    [UIView animateWithDuration:0.5 animations:^{
        cell.layer.transform = CATransform3DMakeScale(1, 1, 0.1);
    }];
    return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataSourceArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
//- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
//{
//    return 70;
//}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
